package com.study.javaBasic.java_io.nio;

import java.io.IOException;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;

/**
 * @Name: FilesTest
 * @Description: java类作用描述
 * @Author: yn
 * @CreateDate: 2023/2/9 11:22
 * @Remark: 特殊说明
 * @Version: 1.0
 */
public class FilesTest {
    public static void main(String[] args) throws IOException {
        Files.walkFileTree(Paths.get("C:\\Users\\yn\\nacos"), new FileVisitor<Path>() {
            @Override
            public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
                System.out.println("目录开始"+dir.getFileName());
                return FileVisitResult.CONTINUE;
            }

            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                System.out.println("文件开始"+file.getFileName());
                return FileVisitResult.CONTINUE;
            }

            @Override
            public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
                System.out.println("访问失败"+file.getFileName());
                return FileVisitResult.SKIP_SIBLINGS;
            }

            @Override
            public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
                System.out.println("目录结束"+dir.getFileName());
                return FileVisitResult.CONTINUE;
            }
        });
    }
}
